import java.util.Scanner;

public class Solution {
    public String trans (String s, int n){
        if(n == 0){
            return s;
        }

        StringBuffer conversion = new StringBuffer();

        for (int i = 0; i < n; i++) {
            //利用ASCII码值进行大小写转化
            if(s.charAt(i)>='A' && s.charAt(i)<='Z'){
                conversion.append((char)(s.charAt(i)-'A'+'a'));
            }else if (s.charAt(i)>='a' && s.charAt(i)<='z'){
                conversion.append((char)(s.charAt(i)-'a'+'A'));
            }else{
                //空格直接复制
                conversion.append(s.charAt(i));
            }
        }
        conversion.reverse();//反转字符串
        for (int i = 0; i < n; i++) {
            int j = i;
            //以空格为界，进行二次反转
            while(j<n && conversion.charAt(j)!=' ')
                j++;

            String temp = conversion.substring(i,j);
            StringBuffer buffer = new StringBuffer(temp);

            temp = buffer.reverse().toString();
            conversion.replace(i,j,temp);//用索引后的单词替换反转后的单词
            i=j;
        }
        return conversion.toString();
    }

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        while(in.hasNext()){
            String s = in.nextLine();;
            int k = in.nextInt();;
            Solution solution = new Solution();
            String newS = solution.trans(s,k);
            System.out.println(newS);
        }
    }
}